<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改成语词典')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-chengyu-edit" th:object="${chengyu}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-2 control-label">解释：</label>
                <div class="col-sm-8">
                    <textarea name="jieshi" class="form-control">[[*{jieshi}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">用法：</label>
                <div class="col-sm-8">
                    <input name="yongfa" th:field="*{yongfa}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">出处：</label>
                <div class="col-sm-8">
                    <input name="chuchu" th:field="*{chuchu}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">例子：</label>
                <div class="col-sm-8">
                    <input name="lizi" th:field="*{lizi}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">典故：</label>
                <div class="col-sm-8">
                    <input id="diangu" name="diangu" th:field="*{diangu}" type="hidden">
                    <div id="editor-diangu" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">英语翻译：</label>
                <div class="col-sm-8">
                    <textarea name="english" class="form-control">[[*{english}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">日语翻译：</label>
                <div class="col-sm-8">
                    <textarea name="japan" class="form-control">[[*{japan}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script src="/js/standalone.js"></script>
    <script src="/js/parser-html.js"></script>
    <script type="text/javascript">
        var prefix = ctx + "dict/chengyu";
        $("#form-chengyu-edit").validate({
            focusCleanup: true
        });

        function prettierFormat(html) {
            try{
                if(prettier == null || prettierPlugins == null) {
                  return html;
                }
                return prettier.format(html, {
                  parser: "html",
                  plugins: prettierPlugins
                });
            }catch(error){
               return html;
            }
        }

        $(function() {
		    $('.summernote').summernote({
		    	placeholder: '请输入内容',
		    	height : 200,
				lang : 'zh-CN',
				followingToolbar: false,
				callbacks: {
	                onImageUpload: function (files) {

	                }
	            }
		    });
		    $('#editor-diangu').summernote('code', prettierFormat($("#diangu").val()));
	    });

        function submitHandler() {
            if ($.validate.form()) {
                $('#diangu').val($('#editor-diangu').summernote('code'));
                let data = $('#form-chengyu-edit').serializeArray()
                $.operate.save(prefix + "/edit", data);
            }
        }

    </script>
</body>
</html>